package office;

import java.util.Arrays;

public class Log {

	Visit[] visits = new Visit[10];
	int indexVisit = 0;
	
	void serchSpaceTimeMaxVisitors(){
		
		int countVisitors = 1;
		SpaceDate[] spaceDateNaxVisitor = new SpaceDate[indexVisit];
		int indexSpaceDateNaxVisitor=0;
		
		for(int i = 0; i < indexVisit ; i++){
			int tmpCountVisitors = 1;
			SpaceDate tmpSpaceDate = visits[i].spaceDate;
			
			for(int j = 0; j < indexVisit; j++){
				
				if(i == j) continue;
				
				if(tmpSpaceDate.chekTotalSpaceDate(visits[j].spaceDate)){
					tmpSpaceDate = tmpSpaceDate.crossingSpaceDate(visits[j].spaceDate);
					tmpCountVisitors++;
				}
				
			}
			
			if(tmpCountVisitors == countVisitors){				
				spaceDateNaxVisitor[indexSpaceDateNaxVisitor] = tmpSpaceDate;
				indexSpaceDateNaxVisitor++;
			}
			else if(tmpCountVisitors > countVisitors){
				spaceDateNaxVisitor = new SpaceDate[indexVisit];
				indexSpaceDateNaxVisitor = 0;
				spaceDateNaxVisitor[indexSpaceDateNaxVisitor] = tmpSpaceDate;		
				countVisitors = tmpCountVisitors;
			}
		}
		
		System.out.println("countVisitors ["+ countVisitors + "] - " + Arrays.toString(spaceDateNaxVisitor));
	}
	 
	
	void addVisit(Visit visit) {
		if (indexVisit >= visits.length) {
			visits = upSizeArray();
		}
		visits[indexVisit] = visit;
		indexVisit++;
	}

	
	Visit[] upSizeArray() {

		int newLength = visits.length * 3 / 2;
		Visit[] newVisits = new Visit[newLength];
		System.arraycopy(visits, 0, newVisits, 0, visits.length);
		return newVisits;
	}

	@Override
	public String toString() {
		return "Log [" + Arrays.toString(visits) + "]";
	}

}



